package com.bosssoft.hr.javase;

import java.util.*;

/**
 * @Description: HashMapExample
 * @Author: WengYu
 * @CreateTime: 2022/05/12 15:44
 */
public class HashMapExample {
    private Map<Integer, User> map = new HashMap<>();

    public User put(Integer key, User value){
        return map.put(key,value);
    }

    public User remove(Integer key){
        return map.remove(key);
    }

    public boolean containsKey(Integer key){
        return map.containsKey(key);
    }

    public void visitByEntrySet(){
        Set<Map.Entry<Integer, User>> entries = map.entrySet();
        for (Map.Entry<Integer, User> entry : entries) {
            System.out.println("Key:"+ entry.getKey()+"---->Value:"+entry.getValue());
        }
    }

    public void visitByKeySet(){
        Set<Integer> keys = map.keySet();
        for (Integer next : keys) {
            System.out.println(map.get(next));
        }

    }

    public void visitByValues(){
        Collection<User> values = map.values();
        Iterator<User> iterator = values.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }



}
